package com.plz.afmt.controller;

import com.plz.shrio.vo.BaseLoginVo;
import com.plz.web.base.dto.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.plz.web.util.ReqResUtil;
import com.plz.web.base.vo.PagerResult;

import javax.validation.Valid;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.plz.web.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.plz.afmt.service.UserService;


import com.plz.afmt.dto.UserDto;
import com.plz.afmt.dto.UserQueryDto;
import com.plz.afmt.vo.UserVo;

/**
 * <p>
 * 用户表 管理
 * </p>
 *
 * @author jzc
 */
@Slf4j
@RestController
@Api(tags = "用户表-管理")
@RequestMapping("/admin/user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 查询分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @PostMapping("/page")
    public Resp<PagerResult<UserVo>> page(@RequestBody Resq<UserQueryDto> requestBean) {
        UserQueryDto dto = getReqData(requestBean);
        PagerResult<UserVo> result = userService.pageQuery(dto);
        return getRes(result);
    }

    @ApiOperation(value = "查询数据")
    @PostMapping("/list")
    public Resp<List<UserVo>> list(@RequestBody Resq<UserQueryDto> requestBean) {
        UserQueryDto dto = getReqData(requestBean);
        List<UserVo> result = userService.listFor(dto);
        return getRes(result);
    }

    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询数据")
    @PostMapping(value = "/detail")
    public Resp<UserVo> getById(@Valid @RequestBody Resq<BaseIdDto> requestBean) {
        BaseIdDto dto = getReqData(requestBean);
        UserVo result = userService.detail(dto.getId());
        return getRes(result);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @PostMapping(value = "/add")
    public Resp<Boolean> add(@Valid @RequestBody Resq<UserDto> requestBean) {
        UserDto dto = getReqData(requestBean);
        Boolean result = userService.addOrUpdate(dto) != null;
        return getRes(result);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新数据")
    @PostMapping(value = "/update")
    public Resp<Boolean> update(@Valid @RequestBody Resq<UserDto> requestBean) {
        UserDto dto = getReqData(requestBean);
        Boolean result = userService.addOrUpdate(dto) != null;
        return getRes(result);
    }

    /**
     * 绑定企业
     */
    @ApiOperation(value = "绑定企业")
    @PostMapping(value = "/binding")
    public Resp<Boolean> binding(@Valid @RequestBody Resq<BaseCodeDto> requestBean) {
        BaseCodeDto dto = getReqData(requestBean);
        Boolean result = userService.binding(dto.getCode());
        return getRes(result);
    }

    /**
     * 解除绑定企业
     */
    @ApiOperation(value = "解除绑定企业")
    @PostMapping(value = "/lifted")
    public Resp<Boolean> lifted(@Valid @RequestBody Resq<BaseIdDto> requestBean) {
        BaseIdDto dto = getReqData(requestBean);
        Boolean result = userService.lifted(dto.getId());
        return getRes(result);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @PostMapping(value = "/del")
    public Resp<Boolean> delete(@Valid @RequestBody Resq<BaseIdsDto> requestBean) {
        BaseIdsDto dto = getReqData(requestBean);
        Boolean result = userService.removeByIds(dto.getIds());
        return getRes(result);
    }

    @ApiOperation(value = "当前登录用户")
    @PostMapping(value = "/me")
    public Resp<UserVo> me(){
        UserVo result = userService.me();
        return getRes(result);
    }

    @ApiOperation(value = "同意用户须知")
    @PostMapping(value = "/notice")
    public Resp<Boolean> notice(){
        Boolean result = userService.notice();
        return getRes(result);
    }
}
